package com.lfg.leetcode.leetcode0;

public class No14LongestCommonPrefix {
    public static String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) {
            return "";
        }
        if (strs.length == 1) {
            return strs[0];
        }
        String firstString = strs[0];
        int j = 1;
        while (j < strs.length) {
            while (!strs[j].startsWith(firstString)) {
                firstString = firstString.substring(0, firstString.length() - 1);
            }
            j++;
        }
        return firstString;
    }

    public static void main(String[] args) {
        System.out.println(longestCommonPrefix(new String[]{}));
    }
}
